package com.atguigu.gulimall.auth.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;


/**
 * @author 满超
 * @date 2020/06/18
 **/
@Configuration
public class RedisSessionConfig {

    /**
     * cookie的sessionId令牌配置
     * @return
     */

    //cookie序列化
    @Bean
    public CookieSerializer cookieSerializer(){
        DefaultCookieSerializer serializer = new DefaultCookieSerializer();
        serializer.setDomainName("gulimall.com");//令牌作用域，防止默认作用域访问不到。解决cookie通过域名访问不同微服务
        serializer.setCookieName("GULISESSION");//修改cookie存储的令牌名字

        return serializer;
    }

    //session序列化
    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer() {
        return new GenericJackson2JsonRedisSerializer();
    }
}
